home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 7 / PC World Interactive 7.iso / program / vbkontrol.exe / IPD_102N.ZIP / FTP.FRM < prev    next >
Text File  |  1995-06-24  |  13KB  |  498 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "FTP Demo - Please refer to RFC959 for more info."
  5.    ClientHeight    =   5385
  6.    ClientLeft      =   1185
  7.    ClientTop       =   1500
  8.    ClientWidth     =   8640
  9.    Height          =   5790
  10.    Left            =   1125
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5385
  13.    ScaleWidth      =   8640
  14.    Top             =   1155
  15.    Width           =   8760
  16.    Begin Frame Frame2 
  17.       BackColor       =   &H00C0C0C0&
  18.       Caption         =   "Operation"
  19.       Height          =   1095
  20.       Left            =   3120
  21.       TabIndex        =   20
  22.       Top             =   1080
  23.       Width           =   1935
  24.       Begin OptionButton oWhat 
  25.          BackColor       =   &H00C0C0C0&
  26.          Caption         =   "List"
  27.          Height          =   255
  28.          Index           =   2
  29.          Left            =   240
  30.          TabIndex        =   23
  31.          Top             =   720
  32.          Width           =   1335
  33.       End
  34.       Begin OptionButton oWhat 
  35.          BackColor       =   &H00C0C0C0&
  36.          Caption         =   "<--Download"
  37.          Height          =   255
  38.          Index           =   1
  39.          Left            =   240
  40.          TabIndex        =   22
  41.          Top             =   480
  42.          Width           =   1455
  43.       End
  44.       Begin OptionButton oWhat 
  45.          BackColor       =   &H00C0C0C0&
  46.          Caption         =   "Upload-->"
  47.          Height          =   255
  48.          Index           =   0
  49.          Left            =   240
  50.          TabIndex        =   21
  51.          Top             =   240
  52.          Value           =   -1  'True
  53.          Width           =   1335
  54.       End
  55.    End
  56.    Begin CommandButton Command2 
  57.       Caption         =   "GO!!"
  58.       Height          =   375
  59.       Left            =   5400
  60.       TabIndex        =   19
  61.       Top             =   1800
  62.       Width           =   1215
  63.    End
  64.    Begin CommandButton Command1 
  65.       Caption         =   "Cancel"
  66.       Height          =   375
  67.       Left            =   6840
  68.       TabIndex        =   18
  69.       Top             =   1800
  70.       Width           =   1095
  71.    End
  72.    Begin Frame Frame1 
  73.       BackColor       =   &H00C0C0C0&
  74.       Caption         =   "PI State"
  75.       Height          =   1335
  76.       Left            =   6960
  77.       TabIndex        =   14
  78.       Top             =   0
  79.       Width           =   1575
  80.       Begin OptionButton oState 
  81.          BackColor       =   &H00C0C0C0&
  82.          Caption         =   "COMMAND"
  83.          Enabled         =   0   'False
  84.          ForeColor       =   &H0000FFFF&
  85.          Height          =   255
  86.          Index           =   2
  87.          Left            =   120
  88.          TabIndex        =   17
  89.          Top             =   960
  90.          Width           =   1335
  91.       End
  92.       Begin OptionButton oState 
  93.          BackColor       =   &H00C0C0C0&
  94.          Caption         =   "WAITING"
  95.          Enabled         =   0   'False
  96.          ForeColor       =   &H000000FF&
  97.          Height          =   255
  98.          Index           =   1
  99.          Left            =   120
  100.          TabIndex        =   16
  101.          Top             =   600
  102.          Width           =   1215
  103.       End
  104.       Begin OptionButton oState 
  105.          BackColor       =   &H00C0C0C0&
  106.          Caption         =   "IDLE"
  107.          Enabled         =   0   'False
  108.          ForeColor       =   &H0000FF00&
  109.          Height          =   255
  110.          Index           =   0
  111.          Left            =   120
  112.          TabIndex        =   15
  113.          Top             =   240
  114.          Value           =   -1  'True
  115.          Width           =   855
  116.       End
  117.    End
  118.    Begin IPPORT IPPort1 
  119.       EOL             =   ""
  120.       InBufferSize    =   2048
  121.       Left            =   1680
  122.       Linger          =   -1  'True
  123.       LocalPort       =   0
  124.       OutBufferSize   =   2048
  125.       Port            =   0
  126.       Top             =   960
  127.    End
  128.    Begin IPDAEMON IPDaemon1 
  129.       EOL             =   ""
  130.       InBufferSize    =   2048
  131.       Left            =   2160
  132.       Linger          =   -1  'True
  133.       OutBufferSize   =   2048
  134.       Port            =   0
  135.       Top             =   960
  136.    End
  137.    Begin OptionButton optBinary 
  138.       BackColor       =   &H00C0C0C0&
  139.       Caption         =   "BINARY"
  140.       Height          =   255
  141.       Index           =   1
  142.       Left            =   1560
  143.       TabIndex        =   13
  144.       Top             =   1800
  145.       Width           =   975
  146.    End
  147.    Begin OptionButton optASCII 
  148.       BackColor       =   &H00C0C0C0&
  149.       Caption         =   "ASCII"
  150.       Height          =   255
  151.       Index           =   0
  152.       Left            =   360
  153.       TabIndex        =   12
  154.       Top             =   1800
  155.       Value           =   -1  'True
  156.       Width           =   975
  157.    End
  158.    Begin CommandButton bConnect 
  159.       Caption         =   "Connect!!"
  160.       Height          =   375
  161.       Left            =   5280
  162.       TabIndex        =   11
  163.       Top             =   180
  164.       Width           =   1335
  165.    End
  166.    Begin TextBox tOutput 
  167.       FontBold        =   0   'False
  168.       FontItalic      =   0   'False
  169.       FontName        =   "Courier New"
  170.       FontSize        =   8.25
  171.       FontStrikethru  =   0   'False
  172.       FontUnderline   =   0   'False
  173.       Height          =   3135
  174.       HideSelection   =   0   'False
  175.       Left            =   0
  176.       MousePointer    =   1  'Arrow
  177.       MultiLine       =   -1  'True
  178.       ScrollBars      =   3  'Both
  179.       TabIndex        =   10
  180.       Top             =   2280
  181.       Width           =   8655
  182.    End
  183.    Begin TextBox tRemote 
  184.       Height          =   285
  185.       Left            =   5280
  186.       TabIndex        =   7
  187.       Text            =   "/pub/README"
  188.       Top             =   1440
  189.       Width           =   2775
  190.    End
  191.    Begin TextBox tLocal 
  192.       Height          =   285
  193.       Left            =   120
  194.       TabIndex        =   6
  195.       Text            =   "C:\FTPTEST.TXT"
  196.       Top             =   1440
  197.       Width           =   2775
  198.    End
  199.    Begin TextBox tPassword 
  200.       Height          =   285
  201.       Left            =   4440
  202.       TabIndex        =   5
  203.       Text            =   "elf@north.pole.com"
  204.       Top             =   720
  205.       Width           =   2295
  206.    End
  207.    Begin TextBox tUserID 
  208.       Height          =   285
  209.       Left            =   1320
  210.       TabIndex        =   4
  211.       Text            =   "anonymous"
  212.       Top             =   720
  213.       Width           =   1575
  214.    End
  215.    Begin TextBox tHost 
  216.       Height          =   285
  217.       Left            =   1320
  218.       TabIndex        =   0
  219.       Text            =   "little"
  220.       Top             =   240
  221.       Width           =   3615
  222.    End
  223.    Begin Label Label1 
  224.       BackStyle       =   0  'Transparent
  225.       Caption         =   "Remote File"
  226.       Height          =   255
  227.       Index           =   4
  228.       Left            =   5280
  229.       TabIndex        =   9
  230.       Top             =   1200
  231.       Width           =   1575
  232.    End
  233.    Begin Label Label1 
  234.       BackStyle       =   0  'Transparent
  235.       Caption         =   "Local File"
  236.       Height          =   255
  237.       Index           =   3
  238.       Left            =   120
  239.       TabIndex        =   8
  240.       Top             =   1200
  241.       Width           =   1575
  242.    End
  243.    Begin Label Label1 
  244.       BackStyle       =   0  'Transparent
  245.       Caption         =   "Password:"
  246.       Height          =   255
  247.       Index           =   2
  248.       Left            =   3360
  249.       TabIndex        =   3
  250.       Top             =   720
  251.       Width           =   975
  252.    End
  253.    Begin Label Label1 
  254.       BackStyle       =   0  'Transparent
  255.       Caption         =   "User ID:"
  256.       Height          =   255
  257.       Index           =   1
  258.       Left            =   120
  259.       TabIndex        =   2
  260.       Top             =   720
  261.       Width           =   855
  262.    End
  263.    Begin Label Label1 
  264.       BackStyle       =   0  'Transparent
  265.       Caption         =   "Host Name:"
  266.       Height          =   255
  267.       Index           =   0
  268.       Left            =   120
  269.       TabIndex        =   1
  270.       Top             =   240
  271.       Width           =   1095
  272.    End
  273. End
  274.  
  275. Option Explicit
  276.  
  277. Dim rLocalAddress As String
  278.  
  279. Dim rResponseCode As Integer
  280. Dim rResponseText As String
  281.  
  282. Const S_IDLE = 0
  283. Const S_WAITING = 1
  284. Const S_COMMAND = 2
  285.  
  286. Const M_UPLOAD = 0
  287. Const M_DOWNLOAD = 1
  288. Const M_LIST = 2
  289.  
  290. Sub bConnect_Click ()
  291.  
  292. tOutput = ""
  293.  
  294. Screen.MousePointer = 11
  295.  
  296. IPPort1.Connected = False 'disconnect previous connection
  297.  
  298. IPPort1.EOL = Chr$(13) & Chr$(10)
  299.  
  300. IPPort1.HostName = tHost
  301. IPPort1.Port = 21
  302.  
  303. IPPort1.Connected = True
  304.  
  305. 'wait for connection - give it 10 seconds
  306. Dim After10Seconds: After10Seconds = Now + 10# / (3600# * 24#)
  307. Do Until Now > After10Seconds
  308.     If IPPort1.Connected Then Exit Do
  309.     DoEvents
  310. Loop
  311. If Not IPPort1.Connected Then
  312.     MsgBox "Connection timed out!!"
  313.     GoTo Done
  314. End If
  315.  
  316. SendCommand ""  'get server welcome message
  317.  
  318. 'login
  319. SendCommand "USER " & tUserID
  320. 'wait for server response
  321. Do: DoEvents: Loop Until rResponseCode <> 0
  322. 'now send password
  323. SendCommand "PASS " & tPassword
  324.  
  325. Done:
  326. Screen.MousePointer = 0
  327.  
  328. End Sub
  329.  
  330. Sub Command1_Click ()
  331.  
  332. SendCommand "ABOR"
  333. Screen.MousePointer = 0
  334.  
  335. End Sub
  336.  
  337. Sub Command2_Click ()
  338.  
  339. PrepareDataPort
  340. Screen.MousePointer = 11
  341. If oWhat(M_UPLOAD) Then
  342.     oWhat(M_UPLOAD).ForeColor = &HFF&
  343.     Open tLocal For Binary As #1
  344.     SendCommand "STOR " & tRemote
  345. ElseIf oWhat(M_DOWNLOAD) Then
  346.     oWhat(M_DOWNLOAD).ForeColor = &HFF&
  347.     Open tLocal For Binary As #1
  348.     SendCommand "RETR " & tRemote
  349. Else 'oWhat(M_LIST) then
  350.     oWhat(M_LIST).ForeColor = &HFF&
  351.     SendCommand "LIST " & tRemote
  352. End If
  353.  
  354. End Sub
  355.  
  356. Sub Form_Load ()
  357.  
  358. IPPort1.HostName = IPPort1.LocalHostName
  359. rLocalAddress = IPPort1.HostAddress
  360.  
  361. End Sub
  362.  
  363. Sub Form_Resize ()
  364.  
  365. tOutput.Width = ScaleWidth
  366. tOutput.Height = Scaleheight - tOutput.Top
  367.  
  368. End Sub
  369.  
  370. Sub IPDaemon1_Connected (ConnectionID As Integer, StatusCode As Integer, Description As String)
  371.  
  372. On Error GoTo FlowControl
  373.  
  374. If oWhat(M_UPLOAD) Then
  375.     Dim Text$
  376.     Do While Not EOF(1)
  377.         Text$ = Input$(1400, #1)
  378.         IPDaemon1.DataToSend(ConnectionID) = Text$
  379.     Loop
  380.     IPDaemon1.Connected(ConnectionID) = False
  381. End If
  382.  
  383. Exit Sub
  384.  
  385. FlowControl:
  386.     
  387. If Err = 25036 Then
  388.     Dim BytesSent%: BytesSent% = IPDaemon1.BytesSent
  389.     If BytesSent% > 0 Then  'strip bytes sent
  390.         Text$ = Mid$(Text$, BytesSent% + 1)
  391.     End If
  392.     DoEvents   'wait a while
  393.     Resume     'try again
  394. Else  'handle other errors here
  395.     MsgBox Error$
  396.     Exit Sub
  397. End If
  398.  
  399. End Sub
  400.  
  401. Sub IPDaemon1_DataIn (ConnectionID As Integer, Text As String, EOL As Integer)
  402.  
  403. If oWhat(M_LIST) Then
  404.     Trace Text
  405. ElseIf oWhat(M_DOWNLOAD) Then
  406.     Put #1, , Text
  407. End If
  408.  
  409. End Sub
  410.  
  411. Sub IPDaemon1_Disconnected (ConnectionID As Integer, StatusCode As Integer, Description As String)
  412.  
  413. Screen.MousePointer = 0
  414. IPDaemon1.Listening = False
  415. Close #1
  416.  
  417. oWhat(M_UPLOAD).ForeColor = 0
  418. oWhat(M_DOWNLOAD).ForeColor = 0
  419. oWhat(M_LIST).ForeColor = 0
  420.  
  421. End Sub
  422.  
  423. Sub IPPort1_DataIn (Text As String, EOL As Integer)
  424.  
  425. 'trace
  426. Trace Text
  427.  
  428. rResponseText = rResponseText & Text
  429.  
  430. 'full line?
  431. If EOL Then
  432.     Trace Chr$(13) & Chr(10)
  433.     If Mid$(Text, 4, 1) = " " Then
  434.         rResponseCode = CInt(Left$(rResponseText, 3))
  435.         rResponseText = Mid$(rResponseText, 5)
  436.         'elaborate error checking should go here
  437.         'please see RFC959 for more information
  438.         If rResponseCode \ 100 = 1 Then
  439.             oState(S_WAITING) = True
  440.         Else
  441.             oState(S_IDLE) = True
  442.         End If
  443.     End If
  444.     rResponseText = ""  'reset buffer
  445. End If
  446.  
  447. End Sub
  448.  
  449. Sub optASCII_Click (Index As Integer)
  450.  
  451. SendCommand "TYPE A"
  452.  
  453. End Sub
  454.  
  455. Sub optBinary_Click (Index As Integer)
  456.  
  457. SendCommand "TYPE I"
  458.  
  459. End Sub
  460.  
  461. Sub PrepareDataPort ()
  462.  
  463. IPDaemon1.Listening = True
  464. Dim Port: Port = IPDaemon1.Port
  465.  
  466. Dim i%, x%, address$
  467. address$ = rLocalAddress
  468. For i% = 1 To 3
  469.     x% = InStr(address$, ".")
  470.     If x% <> 0 Then Mid$(address$, x%, 1) = ","
  471. Next i%
  472.  
  473. SendCommand "PORT " & address$ & "," & Port \ 256 & "," & Port Mod 256
  474.  
  475. End Sub
  476.  
  477. 'sends an FTP command to the server
  478. 'and returns the response code
  479. Sub SendCommand (CommandText$)
  480.  
  481. rResponseCode = 0
  482. If CommandText$ <> "" Then
  483.     Trace CommandText$ & Chr$(13) & Chr$(10)
  484.     oState(S_COMMAND) = True
  485.     IPPort1.DataToSend = CommandText$ & Chr$(10)
  486. End If
  487.  
  488. End Sub
  489.  
  490. Sub Trace (Text As String)
  491.  
  492. tOutput.SelStart = Len(tOutput)
  493. tOutput.SelLength = 0
  494. tOutput.SelText = Text
  495.  
  496. End Sub
  497.  
  498.